package com.winphone.uavc.utils;

import org.junit.Test;

import java.util.Random;
import java.util.UUID;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2017/12/18
 * @Modified By:
 */

public class GeneratorIds {

    /**
     *
     * @param columnId 课程栏目id
     * @param payType 支付方式
     * @param serialNumber 流水号，需要+1处理
     * @return
     */
    public static String getOrderNumber(Long columnId,String payType,int serialNumber){
        return DateUtils.getDateNumber()
                + columnId
                + payType
                + String.format("%05d",serialNumber+1);
    }

    /*
   * 返回长度为【strLength】的随机数，在前面补0
   */
    private static String getFixLenthString(int strLength) {
        Random rm = new Random();
        // 获得随机数
        double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);
        // 将获得的获得随机数转化为字符串
        String fixLenthString = String.valueOf(pross);
        // 返回固定的长度的随机数
        return fixLenthString.substring(1, strLength + 1);
    }

    @Test
    public void test(){
        for (int i = 0; i < 100; i++) {
            System.out.println(String.format("%03d", i+1));
        }
    }

    /**
     *  取UUID 去除-
     * @return
     */
    public static String generatorCouponNo(){
        UUID uuid  =  UUID.randomUUID();
        return "YHQ"+uuid.toString().replaceAll("\\-", "");
    }

    /**
     * 创建指定数量的随机字符串
     *
     * @param numberFlag 是否是数字
     * @param length     位数
     * @return
     */
    public static String createRandom(boolean numberFlag, int length) {
        String retStr = "";
        String strTable = numberFlag ? "1234567890" : "1234567890abcdefghijkmnpqrstuvwxyz";
        int len = strTable.length();
        boolean bDone = true;
        do {
            retStr = "";
            int count = 0;
            for (int i = 0; i < length; i++) {
                double dblR = Math.random() * len;
                int intR = (int) Math.floor(dblR);
                char c = strTable.charAt(intR);
                if (('0' <= c) && (c <= '9')) {
                    count++;
                }
                retStr += strTable.charAt(intR);
            }
            if (count >= 2) {
                bDone = false;
            }
        } while (bDone);
        return retStr;
    }

}
